<template>
	<view>
		<block v-if="loading">
			<empty :loading="true"></empty>
		</block>
		<block v-else>
			
			<arrowNav class="mb10" url="/pages/addStaff/addStaff">
				<view class="plr15 ptb10 flex left">
					<text class="pr5 fz16 sIcon-addCircle bold main"></text>
					<view>
						添加运维人员
					</view>
				</view>
			</arrowNav>
			
			<view class="pd whiteBg bt" v-for="( item , index) in page.list" :key="index">
				<view class="flex">
					<view>
						<view class="bold fz16">
							{{item.name}}
							<view class="tag ml10" :class="{ 'orangeBg' : item.status == 2 }" v-if="item.status == 2">
								{{item.statusStr}}
							</view>
						</view>
						<view class="fz14 gray">{{item.mobile}}</view>
						<view class="red" v-if="item.refuseReason">审核拒绝：{{item.refuseReason}}</view>
					</view>
					<view>
						<view class="btn line" @tap="remove(item.id , index)">移除</view>
					</view>
				</view>
				
			</view>
			
			<empty :loading="false" :list="page.list"></empty>
			
		</block>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				page : {
					list : [] ,
					lastPage : false ,
					pageNumber : 1 ,
					pageSize : 10
				},
				loading : true ,
				refresh : false 
			}
		},
		
		onLoad() {
			this.loadData();
		},
		
		onReachBottom() {
			if (this.page.lastPage) {
				return ;
			}
			this.page.pageNumber ++ ;
			this.loadData();
		},
		
		onPullDownRefresh() {
			if (this.refresh) {
				return ;
			}
			uni.startPullDownRefresh({});
			this.refresh = true ;
			this.page.pageNumber = 1 ;
			this.loadData();
		},
		
		methods: {
			
			remove:function(id,index){
				uni.showModal({
					title:'提示',
					content:'确认移除该运维人员吗？',
					confirmColor:'#3385ff',
					success : (e)=>{
						if(e.confirm){
							var data = {id:id} ;
							this.kit.get("/api/staff/remove",data,res => {
								this.page.list.splice(index,1);
								uni.showToast({
									title: '操作成功',
									icon : 'success'
								});	
							});
						}
					}
				});
			},
			
			loadData:function(e){
				var data = {
					pageNumber : this.page.pageNumber ,
					pageSize : this.page.pageSize
				} ;
				this.kit.get("/api/staff/list",data,res => {
					if (res.page.pageNumber > 1) {
						res.page.list = this.page.list.concat(res.page.list);
					}
					this.page = res.page ;
					this.loading = false ;
					this.refresh = false ;
				});
			},
			
		}
	}
</script>

